# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Contributor: Patrycja Rosa <alpine@ptrcnull.me>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=woodpecker
pkgver=2.3.0
pkgrel=3
pkgdesc="Simple yet powerful CI/CD engine with great extensibility"
url="https://woodpecker-ci.org"
arch="all"
license="Apache-2.0"
pkgusers="woodpecker"
pkggroups="woodpecker"
makedepends="
	go
	go-swag
	sqlite-dev
	"
subpackages="$pkgname-doc $pkgname-openrc"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/woodpecker-ci/woodpecker/releases/download/v$pkgver/woodpecker-src.tar.gz
	0001-we-use-the-prebuild-webui.patch
	woodpecker.initd
	woodpecker.confd
	woodpecker.conf
	fix-cgo.patch
	"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

unpack() {
	mkdir -p $builddir
	tar -xzvf $srcdir/$pkgname-$pkgver.tar.gz -C $builddir
}

build() {
	export TARGETARCH="$(go env GOHOSTARCH)"
	make build -j1 STATIC_BUILD=false
}

check() {
	go test ./...
}

package() {
	install -Dm755 "$builddir"/dist/woodpecker-server \
		"$pkgdir"/usr/bin/woodpecker-server
	install -Dm755 "$builddir"/dist/woodpecker-agent \
		"$pkgdir"/usr/bin/woodpecker-agent
	install -Dm755 "$builddir"/dist/woodpecker-cli \
		"$pkgdir"/usr/bin/woodpecker-cli
	install -Dm 644 "$builddir"/LICENSE \
		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	install -Dm755 "$srcdir"/woodpecker.initd \
		"$pkgdir"/etc/init.d/woodpecker
	install -Dm644 "$srcdir"/woodpecker.confd \
		"$pkgdir"/etc/conf.d/woodpecker

	install -Dm640 -o woodpecker -g woodpecker "$srcdir"/woodpecker.conf \
		"$pkgdir"/etc/woodpecker.conf
	install -dm755 -o woodpecker -g woodpecker "$pkgdir"/var/lib/woodpecker
}

sha512sums="
3dc50ac720dfac5f7f558b3c0168a186b35751741af889d1330f968e8d7c3a34f6451fada002987c22336d14d34c952a94928a3733402f7bb58279bf4f0b9201  woodpecker-2.3.0.tar.gz
aecf28a0e893ef39f4a9c834aab6d9cdfef5a7f01ba5918134e2e7f3784ae102e642b9e247957da9c480ac7486b5f82027bff8df3033e90a503de57597b69917  0001-we-use-the-prebuild-webui.patch
69fe477f805dcb71b0220b9af2b3d0226b2e92f3c46764f37a139bb7303ad7cdb1caa2a711d1f9d22fccb357bbfbecb1c6cba2033c9101a11c0bb67b405c3e55  woodpecker.initd
0be91432e730cb0ad3663bebe7a257437cbefe5fa5c2f3145d621545d6cd2ff89ae41f338a5874166d2b03dc8caab73d26cd4322ed1122d4949cae5d6002b823  woodpecker.confd
cb15d7ff290d9b68d5f63c20401ab622c8a7067d336841c876a6d3325e9d2a3ede3a85b792131d7d77a4126cbdb6f30a5a6113468f1efd736a2c1bbf2bfefbe4  woodpecker.conf
2e7a002378d9005a775efee97012ccf0bf1724382e89e4ff0a75cc9f29c57423d820b0ebdd3b72d5176a6e98ff82b60c9d98671d70e0c24b3e131ce513a520cb  fix-cgo.patch
"
